package org.exmaple.springframework.beans.factory.support;

import org.exmaple.springframework.beans.BeansException;
import org.exmaple.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * @author DeYou
 * @date 2022/10/26
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry{

    private final Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    @Override
    public void registerBeanDefinitionRegistry(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put( beanName,beanDefinition );
    }

    @Override
    protected BeanDefinition getBeanDefinition(String beanName) throws BeansException {
        BeanDefinition beanDefinition = beanDefinitionMap.get( beanName );
        if(beanDefinition ==null) throw new BeansException( " No bean named " + beanName + " ' is defined!" );

        return beanDefinition;
    }
}